package com.xwm93up.basic.integertips;

import java.lang.reflect.Field;

/**
 * @Description: 为什么Java中1000==1000为false, 而100==100为true呢
 * @Author: xwm93up
 * @Since: 2021/10/23 10:04
 */
public class Test1 {
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        /*Integer a = 1000, b = 1000;
        System.out.println(a == b);// false
        System.out.println(a.equals(b));// true
        Integer c = 100, d = 100;
        System.out.println(c == d);// true*/


        Class cache = Integer.class.getDeclaredClasses()[0]; //1
        Field myCache = cache.getDeclaredField("cache"); //2
        myCache.setAccessible(true);//3

        Integer[] newCache = (Integer[]) myCache.get(cache); //4
        newCache[132] = newCache[133]; //5, 步骤5相当于把5的值赋给了4, 导致2+2=5

        int a = 2;
        int b = a + a;
        System.out.printf("%d + %d = %d", a, a, b); //
    }
}
